'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFJkdCtrl
 * @description
 * # FinanceFJkdCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFJkdCtrl', function($scope, $rootScope, openApi, $http, Util, $location, $routeParams, $filter, localStorageService, FormSubmit) {
        $scope.sheetObj = {};
        // 底部关联模块类型选框添加
        var relModuleObj = {},
            selectData, params;
        relModuleObj.sheettitle = "关联模块";
        relModuleObj.callback = function(item) {
            if (item.selectTabContent == "无") {
                $scope.param.relatedModuleName = "无";
                $scope.param.relatedModule = "";
                $scope.param.moduleNo = "";
                return;
            }
            $scope.param.relatedModule = item.selectTab;
            $scope.param.relatedModuleName = item.selectTabContent;
            $scope.param.moduleNo = ""

        }
        $scope.sheetObj.relModuleObj = relModuleObj;
        $scope.showrelModule = function() {
            Util.getModuleRel(Util.JK_MODULE, function(data) {
                $scope.sheetObj.relModuleObj.tabList = data.data
                $scope.showSheet("relModuleObj")
            })

        };
        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };
        $scope.chooseinfo = function() {
            // $routeParams.id通过id确定唯一回显id
            if (!$scope.param.relatedModule) {
                return
            }
            Util.savaParamForReview($scope.param, $routeParams.id);
            // 里面包含了title
            var relModuleObj = {
                name: "FinanceFJkdCtrl",
                selectTab: $scope.param.relatedModule,
                selectTabContent: $scope.param.relatedModuleName
            };
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")

        };
        $scope.submit = function() {
            // 底部类型end
            // $scope.param.type = $scope.sheetObj.relModuleObj.selectTab
            // $scope.param.tentativeCost = "11";
            if (!$scope.param.borAmount) {
                if ($scope.param.borAmount !== 0) {
                    Util.Toast("请填写借款金额");
                    return;
                }
            }
            if (!$scope.param.borrowReason) {
                Util.Toast("请填写借款事由");
                return;
            }
            if (!$scope.param.returnDate) {
                Util.Toast("请填写归还日期");
                return;
            }
            if ($scope.param.relatedModuleName && $scope.param.relatedModuleName !== '无') {
                if (!$scope.param.moduleNo) {
                    Util.Toast("请选择模块编号");
                    return;
                }
            }
            // 提交
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // $scope.param.operationId = -2
            // $scope.param.processId = $routeParams.id
            // $scope.param.url = openApi.borrowMoney
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.borrowMoney
            var options = {};
            options.urlParam = urlParam;
            options.param = $scope.param;
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.borrowMoney
            }
            new FormSubmit(options);
        };
        // 初始化逻辑,如果是修改页面的话则先从接口请求数据回显，再将缓存中的跳转来源删除，方便页面跳转返回之后的回显
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });

        };
        // 初始化
        init();
    });
